package edu.uc.ui.ctrl25;


import com.liuvei.common.RandFun;
import com.liuvei.common.ValidateCodeFun;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;

@org.springframework.stereotype.Repository("ValidateCodeAction")
@org.springframework.context.annotation.Scope("prototype")
public class ValidateCodeAction extends BaseAction {
	
	public String execute(){
		
		//1)生成4位随机数字组成的字符串
		String strCode=RandFun.rand4Num().toString();
		//2)随机字符串放入会话
		ActionContext.getContext().getSession().put("validateCode", strCode);
		
		//3)随机字符串转为图片
		java.awt.image.BufferedImage image= ValidateCodeFun.generalImage(strCode);
		//4)BufferedImage图片，转为字节数组输入流，作为相应管道的输入流
		rspStream=ValidateCodeFun.toByteArrayInputStream(image);
		return Action.SUCCESS;
	}
	//响应管道的输入流
	private java.io.ByteArrayInputStream rspStream;
	public java.io.ByteArrayInputStream getRspStream() {
		return rspStream;
	}
	public void setRspStream(java.io.ByteArrayInputStream rspStream) {
		this.rspStream = rspStream;
	}

	
}
